package logic

import (
	"context"
	"errors"
	"strings"
	"video-hubs/model/mysql"

	"video-hubs/videorpc/internal/svc"
	"video-hubs/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodAddLogic {
	return &GoodAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodAddLogic) GoodAdd(in *videorpc.GoodAddRequest) (*videorpc.GoodAddResponse, error) {
	// todo: add your logic here and delete this line
	data := &mysql.Good{
		UserId:  int(in.UserId),
		SangId:  int(in.SangId),
		Content: in.Content,
	}
	if strings.Contains(in.Content, "欺诈") || strings.Contains(in.Content, "伪劣") {
		return nil, errors.New("评论中包含敏感词")
	}
	if err := data.GoodAdd(mysql.DB); err != nil {
		return nil, err
	}
	return &videorpc.GoodAddResponse{
		GoodId: int64(data.ID),
	}, nil
}
